package com.czk.variabledeployment;

import com.czk.pojo.Holiday;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 流程实例的启动
 * 设置流程变量的值
 * @Author ChenZhangKun
 * @Date 2020/9/11 14:40
 */
@SuppressWarnings("all")
public class StartInstance {
    public static void main(String[] args) {
        startInstance_1();
    }

    /**
     * 正常启动，完成任务是需要指定流程变量
     */
    public static void startInstance_2(){
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //
        RuntimeService runtimeService = processEngine.getRuntimeService();
        // 启动流程->正常启动
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("leave");
        System.out.println("实例id "+processInstance.getId());
    }

    /**
     * 在启动时将流程变量添加进去
     */
    public static void startInstance_1(){
        //
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //
        RuntimeService runtimeService = processEngine.getRuntimeService();
        // 启动流程
        // 设置流程变量
        Holiday holiday=new Holiday();
        holiday.setBeginTime(new Date());
        holiday.setNum(5.0f);
        holiday.setHolidayName("陈彰坤");
        holiday.setId(1);
        holiday.setReason("休息");
        holiday.setType("调休");
        // 设置map
        Map<String,Object> map=new HashMap<>(10);
        map.put("holiday",holiday);
        // 启动流程实例
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("leave", map);
        // 得到流程实例id
        System.out.println(processInstance.getName());
        System.out.println(processInstance.getProcessDefinitionId());
    }
}
